package cn.com.pc.content.controller;

import cn.com.pc.content.service.ContentImportService;
import cn.com.pc.content.service.TagImportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.server.ResponseStatusException;

/**
 * 辅助功能接口
 */
@RestController
@RequestMapping("/extra")
public class ExtraController {

    @Autowired
    private TagImportService tagImportService;

    @Autowired
    private ContentImportService contentImportService;

    /**
     * 从旧版内容平台导入标签
     * 注意：需要先执行标签树初始化sql
     */
//    @PostMapping("/import/pcp-tags")
    public void importTagsFromPcp() {
        tagImportService.importTagsFromPcpDB();
    }


    /**
     * 从第一版内容平台更新内容数据
     */
//    @PostMapping("/import/pcp-content")
    public void updateContentFromPcp() {
        contentImportService.updateContentFromPcpES();
    }


    /**
     * 从产品库更新产品标签
     */
    @PostMapping("/import/rac-tags")
    public void importTagsFromRac(@RequestParam(defaultValue = "0") int from, @RequestParam(defaultValue = "0") int to) {
        if (from < to) {
            throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "日期范围有误");
        }
        tagImportService.importTagsFromRacDB(from, to);
    }

}
